<?php

namespace CtyunOss\struct;

use Carbon\Carbon;
use CtyunOss\cors\ArrayObject;
use CtyunOss\interfaces\FileObjectInterface;

/**
 * Class FileObject
 * @package CtyunOss\struct
 *
 * @author  Violet_Ice紫冰 <violetice@aliyun.com>
 * @create  2020-06-27 10:46:48
 */
class FileObject extends ArrayObject implements FileObjectInterface
{
    /** @var string 文件对象名称 */
    public $Key;

    /** @var Carbon 最后修改时间 */
    public $LastModified;

    /** @var string 文件对象实体标签 */
    public $ETag;

    /** @var int 文件大小 */
    public $Size;

    /** @var string 存储类型 */
    public $StorageClass;

    /** @var int 对象类型: 0 = 目录, 1 = 文件 */
    public $type;

    /** @var Owner 所有者 */
    public $Owner;

    public function __construct(array $data = [])
    {
        parent::__construct($data);
        $this->LastModified = Carbon::parse($data['LastModified']);
        $this->Size         = (int)$data['Size'];
        $this->Owner        = new Owner($data['Owner']);

        $this->type = static::FILE;
        if (preg_match('/\/$/', $this->Key)) {
            $this->type = static::DIR;
        }
    }
}